package com.fivetalks.domain;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;

@Entity
@Table(name="POST")
public class Post implements Serializable{
	/**
	 * 
	 */
	private static final long serialVersionUID = -7664703999791493592L;
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private Long id;
	
	@Column(name="name", length=20)
	private String name;
	
	@Column(name="content", columnDefinition="TEXT")
	private String content;
	
	@Column(name="passwd", length=8)
	private String passwd;
	
	@Column(name="regdate")
	private Date regdate;
	
	@OneToMany(mappedBy = "post", fetch = FetchType.LAZY, cascade = {CascadeType.ALL})
	@OrderBy("id ASC" )
	private List<Reply> replys;
	
	
	public Post() {
		setRegdate(new Date());
	}
	
	public void setRegdate(Date regdate) {
		this.regdate = regdate;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public String getPasswd() {
		return passwd;
	}

	public void setPasswd(String passwd) {
		this.passwd = passwd;
	}

	public List<Reply> getReplys() {
		return replys;
	}

	public void setReplys(List<Reply> replys) {
		this.replys = replys;
	}
	
	public void addReply(Reply reply){
		if(replys==null){
			replys=new ArrayList<Reply>();
		}
		replys.add(reply);
	}
	
	
	public Date getRegdate() {
		return regdate;
	}
	
} //POST
